package live.api.impl;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import live.common.PropertiesManager;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

public class SanIsMember {
	
	
	public  static String getFlag_TEL(String bh,String pwd) throws Exception{
		String namespace_uri=PropertiesManager.getInstance().returnPropValue("SAN_MEMBER_NAMESPACE");
		Service  service=new Service();   
		Call   call   =   (Call)service.createCall();   
		call.setReturnType(XMLType.XSD_STRING);
		call.setTargetEndpointAddress(PropertiesManager.getInstance().returnPropValue("SAN_MEMBER_URL"));   
		call.setOperationName(new QName(namespace_uri, "GetFlag_TEL"));
		
		// 所需参数
		call.addParameter(new QName(namespace_uri,"bh"),XMLType.XSD_STRING,ParameterMode.IN);
		call.addParameter(new QName(namespace_uri,"pwd"),XMLType.XSD_STRING,ParameterMode.IN);
		// 执行，获取接口返回值
		return call.invoke(new Object[]{bh,pwd}).toString();
	}
	
	
	/**
	 * 验证是否为业务系统会员
	 * @param userId
	 * @return 0:业务系统会员，1:非业务系统会员
	 */
	public int isMember(String userId) {
		int result_count=0;
		Service service = new Service();
		Call call;
		try {
			String namespace_uri=PropertiesManager.getInstance().returnPropValue("SAN_MEMBER_NAMESPACE");
			call = (Call) service.createCall();
			call.setReturnType(XMLType.XSD_STRING);
			call.setTargetEndpointAddress(PropertiesManager.getInstance().returnPropValue("SAN_MEMBER_URL"));
			call.setOperationName(new QName(namespace_uri, "IsMember"));

			// 所需参数
			call.addParameter(new QName(namespace_uri, "bh"), XMLType.XSD_STRING,
					ParameterMode.IN);
			// 执行，获取接口返回值
			String result = call.invoke(new Object[] { userId }).toString();
			switch (Integer.parseInt(result)) {
			case 0:
				result_count=0;
				break;
			case 1:
				result_count=1;
				break;	
			}
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result_count;
	}
	
	public static void main(String[] args) {
		System.out.println(new SanIsMember().isMember("sxk1026"));
		System.out.println(new SanIsMember().isMember("00006"));
	}
}
